import { Entity, Column, OneToMany, OneToOne } from "typeorm";

import {
  GemSku,
  AppDueSku,
  INTEGER_PG,
  MarketOrder,
  ENUM_PAYMENT,
  MarketAccount,
  PaymentWeChatMp,
  MarketOrderGateway,
  ENUM_PAYMENT_STATUS,
  MarketAccountGateway,
} from "qqlx-core";

import { TransformerInteger } from "@lib/orm.transfor.number";

import { OwnerIdSchema } from "@/alpha/ext.id.base";
import { OrderSchema } from "@/alpha/ext.com.order";
import { TransformerEnum } from "@lib/orm.transfor.enum";

@Entity({ name: MarketAccountGateway.relations })
export class MarketAccountSchema extends OwnerIdSchema implements MarketAccount {
  @Column({ transformer: new TransformerInteger() })
  gems: INTEGER_PG = 0;
}

@Entity({ name: MarketOrderGateway.relations })
export class MarketOrderSchema extends OrderSchema implements MarketOrder {
  @Column({ transformer: new TransformerEnum(Object.values(ENUM_PAYMENT), ENUM_PAYMENT.NONE) })
  paymentType: ENUM_PAYMENT = ENUM_PAYMENT.NONE;

  @Column({ transformer: new TransformerEnum(Object.values(ENUM_PAYMENT_STATUS), ENUM_PAYMENT_STATUS.NONE) })
  paymentStatus: ENUM_PAYMENT_STATUS = ENUM_PAYMENT_STATUS.NONE;

  @OneToOne("PaymentWeChatMpSchema", (s: PaymentWeChatMp) => s.justMarketOrder)
  justPaymentWeChatMp!: PaymentWeChatMp;

  @OneToMany("GemSkuSchema", (s: GemSku) => s.justMarketOrder)
  joinGemSkuList!: GemSku[];

  @OneToMany("AppDueSkuSchema", (s: AppDueSku) => s.justMarketOrder)
  joinAppDueSkuList!: AppDueSku[];
}
